<template lang="html">
  <div class="time_select">
    <div class="time_active" @click="openSelect">
      <div class="time_active_txt" :class="this.is_open ? 'open' : ''">
        <span>{{name}}</span>
        <div class="down_icon" :class=" this.is_open ? 'show' : ''"></div>
      </div>
    </div>
    <div class="time_long_list" v-if="is_open">
      <template v-for="(item, index) in time_item" :index="index">
        <div class="time-item" @click="itemOnclick(item)" :class="val === item.val ? 'select-active' : ''" :key="index">{{item.name}}</div>
      </template>
    </div>
    <div class="time_msk" v-if="is_open"></div>
  </div>
</template>

<script>

export default {
  data () {
    return {
      is_open: false,
      time_item: [{
        val: '1d',
        name: '今天'
      }, {
        val: '7d',
        name: '近7天'
      }, {
        val: '3m',
        name: '近三个月'
      }, {
        val: '6m',
        name: '近半年'
      }, {
        val: '1y',
        name: '近一年'
      }, {
        val: 'all',
        name: '全部'
      }],
      val: '7d',
      name: '近7天'
    }
  },
  created () {
    console.log(this.$route)
  },
  methods: {
    openSelect () {
      this.is_open = !this.is_open
      console.log(this.is_open)
    },
    itemOnclick (ags) {
      console.log(ags)
      var val = ags.val
      var name = ags.name
      this.val = val
      this.name = name
      this.openSelect()
      this.$emit('selectTime', val)
    }
  }
}
</script>
<style lang="scss" scoped>
.time_select {
  height: 31px;
  position: relative;
}

.time_active {
  font-size: 13px;
  height: 31px;
  padding: 0 35px 0 25px;
  background: #fff;
  line-height: 31px;
  position: relative;
  z-index: 9;
  color: #999;
}
.time_active_txt .open {
  color: #e91f3f;
}
.time_active_txt {
  position: relative;
  padding-right: 35px;
  display: inline-block;
}
.down_icon {
  width: 10px;
  height: 10px;
  right: 10px;
  top: 11px;
  position: absolute;
  -webkit-transition: -webkit-transform 0.5s;
  -moz-transition: -moz-transform 0.5s;
  -o-transition: -o-transform 0.5s;
  transition: transform 0.5s;
  background: url('https://mjmh.meijiameihuo.com/wechat/images/common/down.png') no-repeat center;
  background-size: contain;
}
.down_icon .show {
  animation: rotating 0.6s;
  -webkit-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  transform: rotate(180deg);
}
.time_long_list {
  font-size: 13px;
  position: absolute;
  z-index: 9;
  top: 31px;
  left: 0;
  width: 100%;
  background: #fff;
}

.time_long_list .time-item {
  height: 50px;
  line-height: 50px;
  text-align: left;
  padding: 0 10px;
  border-bottom: .5px solid #edeff2;
  margin: 0 15px;
  background: #fff;
  color: #333333;
  font-size: 14px
}

.time_long_list .select-active {
  color: #e91f3f;
}
.time_msk {
  background:rgba(0,0,0,0.2);
  height: 100vh; width: 100vw;
  position: fixed;
  top: rem(75); left: 0;
  z-index: 1;
}
</style>
